﻿using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;

namespace MiniAspNetCore
{
    /// <summary>
    /// 为HttpListener 所作的适配
    /// </summary>
    public class HttpListenerFeature : IHttpRequestFeature, IHttpResponseFeature
    {
        private readonly HttpListenerContext _context;

        public HttpListenerFeature(HttpListenerContext httpListenerContext)
        {
            this._context = httpListenerContext;
        }

        Uri IHttpRequestFeature.Url => _context.Request.Url;

        NameValueCollection IHttpRequestFeature.Headers => _context.Request.Headers;

        NameValueCollection IHttpResponseFeature.Headers => _context.Response.Headers;

        Stream IHttpRequestFeature.Body => _context.Request.InputStream;

        Stream IHttpResponseFeature.Body => _context.Response.OutputStream;

        int IHttpResponseFeature.StatusCode => _context.Response.StatusCode;
    }
}
